package cn.kgc.controller;

import cn.kgc.pojo.Auditstate;
import cn.kgc.pojo.Company;
import cn.kgc.service.CompanyService;
import cn.kgc.util.Page;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Component
@EnableScheduling
public class CompanyController {
    @Reference
    private CompanyService companyService;
    @Autowired
    private JavaMailSender javaMailSender;
    @RequestMapping("/page.json")
    public Page queryByPage(String companyName,Integer index, Integer size){
       Page page=companyService.queryByPage(companyName,index,size);
       return page;
    }
    @RequestMapping("/selectById.json")
    public Company selectById(Integer companyid){
        return companyService.findById(companyid);
    }
    @RequestMapping("/selectAllAuditstate.json")
    public List<Auditstate> selectAllAuditstate(){
        return companyService.selectAllAuditstate();
    }
    @RequestMapping("/update.json")
    public int update(Integer companyId,Integer auditState){

       return companyService.update(companyId,auditState);

    }
    @RequestMapping("/email.json")
    public void email(Integer companyId,String texts){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        String emails=companyService.seleceEmail(companyId);
        mailMessage.setFrom("liuchuang_java@126.com");
        mailMessage.setTo(emails);
        mailMessage.setSubject("审核回复");
        mailMessage.setText(texts);
        javaMailSender.send(mailMessage);
    }

}
